package com.htfyun.ft.agingtest;

import android.content.Context;
import android.content.SharedPreferences;

import com.htfyun.ft.FTApplication;

public class AgingSharedPreference {

    private final static String AGING_SHARED_PREF_NAME = "aging_shared_preferences";

    public static boolean getBoolean(String name, boolean defValue) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        return sp.getBoolean(name, defValue);
    }

    public static void setBoolean(String name, boolean value) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sp.edit();

        editor.putBoolean(name, value);

        editor.apply();
    }

    public static int getInt(String name, int defValue) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        return sp.getInt(name, defValue);
    }

    public static void setInt(String name, int value) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sp.edit();

        editor.putInt(name, value);

        editor.apply();
    }

    public static long getLong(String name, long defValue) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);
        return sp.getLong(name, defValue);
    }

    public static void setLong(String name, long value) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putLong(name, value);
        editor.apply();
    }

    public static float getFloat(String name, float defValue) {

        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);
        return sp.getFloat(name, defValue);
    }

    public static void setFloat(String name, float value) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putFloat(name, value);
        editor.apply();
    }

    public static String getString(String name) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        return sp.getString(name, "");
    }

    public static void setString(String name, String value) {
        final Context context = FTApplication.getContext();

        SharedPreferences sp = context.getSharedPreferences(AGING_SHARED_PREF_NAME, Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sp.edit();

        editor.putString(name, value);

        editor.apply();
    }
}
